package com.gainloop.Api;

import org.json.JSONException;
import org.json.JSONObject;

import com.gainloop.Api.Entity.EntityAbstract;

public abstract class ApiResponseAbstract<E, T extends EntityAbstract> extends ApiResponse
{	
	protected E _data;
	
	private Class<T> _classT;

	
	public ApiResponseAbstract(int retCode, E data, String error, Class<T> classT)
	{
		super(retCode, null, error);
		
		_retCode = retCode;
		_data = data;
		_error = error;
		
		_classT = classT;
	}
	
	public ApiResponseAbstract(JSONObject response, Class<T> classT) throws JSONException
	{
		super(response);
		_classT = classT;
		
		_retCode = response.optInt("code");
		_data = _getData(response);
		_error = response.optString("error");
	}
	
	public E getData()
	{
		return _data;
	}
	
	protected abstract E _getData(JSONObject response) throws JSONException;
	
	protected Class<T> getClassT()
	{
		return _classT;
	}
	
}
